package cn.hznc.controller.uploadfilestrategy;

import org.simpleframework.xml.strategy.Strategy;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author：Administrator
 * @Date：2024/1/4 10:42
 */
public class Context{

    private UploadFileStrategy uploadFileStrategy;



    public Context(UploadFileStrategy uploadFileStrategy){
        this.uploadFileStrategy = uploadFileStrategy;
    }

    public Context(){

    }


    public void uploadByStrategy(String flag , MultipartFile file , String fileName){
        Map<String, UploadFileStrategy> strategyMap = new HashMap<>(8);
        strategyMap.put("1",new UploadMinio());
        strategyMap.put("2",new UploadLocal());
        Context context = new Context(strategyMap.get(flag));
        context.uploadFile(file , fileName);
    }

    public void uploadFile(MultipartFile file , String fileName){
        this.uploadFileStrategy.uploadFile(file , fileName);
    }
}
